package com.lightsaber.trade.as.dao.category;

import java.util.List;

import org.springframework.stereotype.Component;

import com.lightsaber.trade.as.entity.category.CategoryNode;
import com.lightsaber.trade.core.dao.BaseDao;

@Component
public class CategoryNodeDao extends BaseDao<CategoryNode, String> {

    public List<CategoryNode> findAllByParentIsNull() {
        isNull("parent");
        return list();
    }

    public List<CategoryNode> findAllByParentIsNotNull() {
        isNotNull("parent");
        return list();
    }

    public CategoryNode findByCategoryId(final String categoryId) {
        return eq("category.id", categoryId).isNull("parent").unique();
    }

    public List<CategoryNode> findAllByNameLike(final String name) {
        like("name", name);
        return list();
    }

    public List<CategoryNode> findByParentIdAndCategoryNodeName(final String parentId,
            final String name) {
        eq("parent.id", parentId);
        eq("name", name);
        return list();
    }

}
